/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.hitechbangla.fctu.form;
 

import fctu.simulator.HTB_MAIN;
import com.hitechbangla.fctu.base.aircraft.*;
import javax.swing.JOptionPane;

/**
 *
 * @author Hi-techbangla_2
 */
public class ChangeCallSign extends javax.swing.JFrame {

    /**
     * Creates new form ChangeCallSign
     */
    public ChangeCallSign() {
        initComponents();
        combo_data();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    public void combo_data()
    {
        for(int i=0; i<HTB_MAIN.gameScene.airCraftList.size();i++)
        {
            jComboBox1.addItem(HTB_MAIN.gameScene.airCraftList.get(i).getAircraftState().getCallSign());
        }
    }
    public void getSelectedData()
    {
        String s =jComboBox1.getSelectedItem().toString();
    }
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jComboBox1 = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        CallSignInput = new javax.swing.JTextField();
        jButton1Ok = new javax.swing.JButton();
        jButton2Cancel = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] {}));
        jComboBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox1ActionPerformed(evt);
            }
        });

        jLabel1.setText("CallSignList");

        jLabel2.setText("Changed Call Sign");

        CallSignInput.setText("");
        CallSignInput.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CallSignInputActionPerformed(evt);
            }
        });

        jButton1Ok.setText("Ok");
        jButton1Ok.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1OkActionPerformed(evt);
            }
        });

        jButton2Cancel.setText("Cancel");
        jButton2Cancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2CancelActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(28, 28, 28)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2)
                    .addComponent(jButton1Ok))
                .addGap(33, 33, 33)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton2Cancel)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(jComboBox1, javax.swing.GroupLayout.Alignment.LEADING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(CallSignInput, javax.swing.GroupLayout.Alignment.LEADING)))
                .addContainerGap(74, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(35, 35, 35)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(59, 59, 59)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(CallSignInput, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 72, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1Ok)
                    .addComponent(jButton2Cancel))
                .addGap(71, 71, 71))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1ActionPerformed
        // TODO add your handling code here:
        
    }//GEN-LAST:event_jComboBox1ActionPerformed

    private void jButton2CancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2CancelActionPerformed
        // TODO add your handling code here:
        this.setVisible(false);
        this.dispose();
    }//GEN-LAST:event_jButton2CancelActionPerformed

    private void jButton1OkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1OkActionPerformed
        // TODO add your handling code here:
        if(checkTextFieldsEmpty())
        {
            JOptionPane.showMessageDialog(this, "Enter all the fields!");
        }
        else
        {
            String selectedCallSign =jComboBox1.getSelectedItem().toString();
            String InputCallSign=CallSignInput.getText().toString();
            for(int i=0; i<HTB_MAIN.gameScene.airCraftList.size();i++)
            {
               if(HTB_MAIN.gameScene.airCraftList.get(i).getAircraftState().getCallSign().toString().equals(selectedCallSign)&& InputCallSign.length()==3) 
                   HTB_MAIN.gameScene.airCraftList.get(i).getAircraftState().setCallSign(InputCallSign);
            }
            
        }
    }//GEN-LAST:event_jButton1OkActionPerformed

    private void CallSignInputActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CallSignInputActionPerformed
        // TODO add your handling code here:
        
    }//GEN-LAST:event_CallSignInputActionPerformed
  
    private boolean checkTextFieldsEmpty()
    {
        if(CallSignInput.getText().trim().equals(""))
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(ChangeCallSign.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(ChangeCallSign.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(ChangeCallSign.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(ChangeCallSign.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new ChangeCallSign().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    public javax.swing.JTextField CallSignInput;
    private javax.swing.JButton jButton1Ok;
    private javax.swing.JButton jButton2Cancel;
    public javax.swing.JComboBox jComboBox1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    // End of variables declaration//GEN-END:variables
}
